macro(backup_variable variable)
    if(DEFINED "${variable}")
        set("_${variable}_defined" TRUE)
        set("_${variable}_bak" "${${variable}}")
    else()
        set("_${variable}_defined" FALSE)
    endif()
endmacro()

macro(restore_variable variable)
    if("${_${variable}_defined}")
        set("${variable}" "${_${variable}_bak}")
        unset("_${variable}_bak")
    else()
        unset("${variable}")
    endif()
    unset("_${variable}_defined")
endmacro()
